const BASEURL = 'https://www.uinav.com'
import store from '@/store'

export const request = ({
  url,
  method = 'GET',
  data = {},
  header = {},
  tip = '拼命加载中...',
  needAuth = false
}) => {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title: tip
    })

    if (needAuth) {
      header.Authorization = store.getters['m_user/getToken']
    }

    uni.request({
      url: `${BASEURL}${url}`, //仅为示例，并非真实接口地址。
      method,
      data,
      header,
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        uni.hideLoading()
      }
    })
  })
}
